public class Solution {
 public int reverse(int x) {
        int flag = 1;
        StringBuilder sb = new StringBuilder(String.valueOf(x));
        if(sb.charAt(0) == '-') {
            sb.deleteCharAt(0);
            flag = -1;
        }
        if(sb.charAt(0) == '+') {
            sb.deleteCharAt(0);
        }
        StringBuilder reverse = sb.reverse();
        try {
            return flag * Integer.parseInt(reverse.toString());
        } catch(Exception e) {
            return 0;
        }
    }
}